package com.zhuoyue.biz.core.api.service.impl.device;

import com.zhuoyue.biz.core.api.domain.DeviceAndGatewayDO;
import com.zhuoyue.biz.core.api.dto.req.ControlReq;
import com.zhuoyue.biz.core.command.cmd.common.faa.MultiFunctionSwitch0Faa8A09;
import com.zhuoyue.biz.core.command.cmd.common.faa.base.BaseSetCmd;
import com.zhuoyue.biz.core.command.service.CmdSqlHandleService;
import com.zhuoyue.common.constant.ControlType;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 卓悦面板个性业务处理
 *
 * @author wjming
 */
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ZhuoYueMainBanCommon {
    private final CmdSqlHandleService cmdSqlHandleService;

    public String zhuoYueMainBanDeal(@NotNull String way, @NotNull DeviceAndGatewayDO deviceAndGatewayDO, @NotNull ControlReq controlReq) {
        String cmd;
        String sceneId = controlReq.getActions().get("sceneId") + "";
        if (StringUtils.isNotEmpty(sceneId) && ControlType.Set.SCENE_SET_REQUEST.equals(controlReq.getControlType())) {
            String code6 = cmdSqlHandleService.getSceneCode(controlReq.getActions().get("sceneId") + "");
            cmd = BaseSetCmd.set(deviceAndGatewayDO, controlReq, code6);
        } else {
            cmd = MultiFunctionSwitch0Faa8A09.control(deviceAndGatewayDO, controlReq, way);
        }
        return cmd;
    }
}
